package cn.sinjet.adapter;

import java.util.List;

import com.mgroup.wazehelper.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import cn.sinjet.database.DAOFactory;
import cn.sinjet.database.OBDDAO;
import cn.sinjet.entity.MyObdItemData;
import cn.sinjet.viewmodel.PageDefine;
import cn.sinjet.viewmodel.ViewModel;

public class MyObdListAdapter extends BaseAdapter {

	private final static String TAG = MyObdListAdapter.class.getSimpleName();
	
	private List<String> m_listData;
	private Context m_context;

	public MyObdListAdapter(Context context, List<String> objects) {

		// TODO Auto-generated constructor stub
		m_context = context;
		m_listData = objects;

	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
        final ViewHolder holder;
		if (convertView == null) {
			convertView = LayoutInflater.from(m_context).inflate(
					R.layout.obd_list_item_view, null);
			holder = new ViewHolder();
			holder.title =  (TextView) convertView.findViewById(R.id.obd_list_item_title);
//			holder.enter = (ImageView)conVertView.findViewById(R.id.)
			convertView.setTag(holder);
			/*convertView.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					String title = m_listData.get(Integer.parseInt(holder.title.getTag().toString()));
					OBDDAO obdDao = DAOFactory.getInstance().getOBDDao();
					if(obdDao == null)
						return;
					
					 MyObdItemData data = obdDao.getObdItemData(title);
	                 
					if (data != null) {
						ViewModel.getIns().setViewProperty(R.id.obd_discription_title, title);
						ViewModel.getIns().setViewProperty(R.id.obd_discription_text_chinese_name, data.m_strChineseName);
						ViewModel.getIns().setViewProperty(R.id.obd_discription_text_english_name, data.m_strEnglishName);
						ViewModel.getIns().setViewProperty(R.id.obd_discription_text_text_obd_explain, data.m_strCategory);
						ViewModel.getIns().setViewProperty(R.id.obd_discription_text_obd_about, data.m_strDiscription);
						ViewModel.getIns().jumpPage(PageDefine.PAGE_OBD_DISCRIPTION);
					}
				}
			});*/
		}else{
			holder = (ViewHolder)convertView.getTag();
		}

		String item = m_listData.get(position);
		if (item != null) {
//			final TextView tvObd = (TextView) convertView.findViewById(R.id.obd_list_item_bt_go_to_discription);
			holder.title.setText(item);
			holder.title.setTag(position);
		}
		
		return convertView;
	}

	public static class ViewHolder{
		TextView title;
//		ImageView enter;
	}
	public void setListData(List<String> objects)
	{
		m_listData.clear();
		m_listData = objects;
		notifyDataSetChanged();
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return m_listData.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return m_listData.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}
	
	
}
